package com.zhuo.project.k3.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zhuo.common.utils.poi.ExcelUtil;
import com.zhuo.framework.aspectj.lang.annotation.Log;
import com.zhuo.framework.aspectj.lang.enums.BusinessType;
import com.zhuo.framework.web.controller.BaseController;
import com.zhuo.framework.web.domain.AjaxResult;
import com.zhuo.framework.web.page.TableDataInfo;
import com.zhuo.project.k3.domain.ZzMaterialUnit;
import com.zhuo.project.k3.service.IZzMaterialUnitService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * 卓正计量单位信息Controller
 * 
 * @author ruoyi
 * @date 2020-03-18
 */
@Api("物料计量单位主数据同步管理")
@RestController
@RequestMapping("/k3/unit")
public class ZzMaterialUnitController extends BaseController
{
    @Autowired
    private IZzMaterialUnitService zzMaterialUnitService;

    /**
     * 查询卓正计量单位信息列表
     */
    @PreAuthorize("@ss.hasPermi('k3:unit:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZzMaterialUnit zzMaterialUnit)
    {
        startPage();
        List<ZzMaterialUnit> list = zzMaterialUnitService.selectZzMaterialUnitList(zzMaterialUnit);
        return getDataTable(list);
    }

    /**
     * 导出卓正计量单位信息列表
     */
    @PreAuthorize("@ss.hasPermi('k3:unit:export')")
    @Log(title = "卓正计量单位信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ZzMaterialUnit zzMaterialUnit)
    {
        List<ZzMaterialUnit> list = zzMaterialUnitService.selectZzMaterialUnitList(zzMaterialUnit);
        ExcelUtil<ZzMaterialUnit> util = new ExcelUtil<ZzMaterialUnit>(ZzMaterialUnit.class);
        return util.exportExcel(list, "unit");
    }

    /**
     * 获取卓正计量单位信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('k3:unit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(zzMaterialUnitService.selectZzMaterialUnitById(id));
    }

    /**
     * 新增卓正计量单位信息
     */

    @ApiOperation("同步计量单位主数据")
    @ApiImplicitParam(name = "zzMaterialUnit", value = "同步计量单位主数据", dataType = "ZzMaterialUnit")
    @PreAuthorize("@ss.hasPermi('k3:unit:add')")
    @Log(title = "卓正计量单位信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZzMaterialUnit zzMaterialUnit)
    {
        return toAjax(zzMaterialUnitService.insertZzMaterialUnit(zzMaterialUnit));
    }

    /**
     * 修改卓正计量单位信息
     */
    @PreAuthorize("@ss.hasPermi('k3:unit:edit')")
    @Log(title = "卓正计量单位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZzMaterialUnit zzMaterialUnit)
    {
        return toAjax(zzMaterialUnitService.updateZzMaterialUnit(zzMaterialUnit));
    }

    /**
     * 删除卓正计量单位信息
     */
    @PreAuthorize("@ss.hasPermi('k3:unit:remove')")
    @Log(title = "卓正计量单位信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zzMaterialUnitService.deleteZzMaterialUnitByIds(ids));
    }
}
